package com.xyzq.cgate.admin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xyzq.cgate.admin.mapper.SignMapper;
import com.xyzq.cgate.admin.service.SignService;
import com.xyzq.cgate.common.constant.ZkPathConstants;
import com.xyzq.cgate.common.entity.Plugin;
import com.xyzq.cgate.common.entity.Sign;
import org.I0Itec.zkclient.ZkClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenchen
 * @since 2019-06-25
 */
@Service
public class SignServiceImpl extends ServiceImpl<SignMapper, Sign> implements SignService {

    @Autowired
    private ZkClient zkClient;

    @Override
    public void removeAllZkDataByParentPath(String parentPath) {
        if (zkClient.exists(parentPath)) {
            zkClient.deleteRecursive(parentPath);
        }
    }

    @Override
    public void insertSignDataToZk(List<Sign> signs) {
        String signZkPath = ZkPathConstants.SIGN_PARENT_PATH;
        if(!zkClient.exists(signZkPath)) {
            zkClient.createPersistent(signZkPath, true);
        }
        zkClient.writeData(signZkPath, signs);
    }


}
